#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#第1行注释可以让这个hello.py文件直接在Unix/Linux/Mac上运行，
#第2行注释表示.py文件本身使用标准UTF-8编码：
import requests
import json
import re
import os
start_url='https://www.ximalaya.com/revision/play/album?albumId=237771&pageNum={}&pageSize=30'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
for i in range(2):
    url=start_url.format(i+1)
    r=requests.get(url,headers=headers)#模拟人为操作浏览器
    content=r.content.decode()
    json_obj=json.loads(content)
    list=json_obj['data']['tracksAudioPlay']
    #{"data":{"tracksAudioPlay":[{"src":"http://audio.xmcdn.com/group50/M08/4A/27/wKgKnVvXEF_T7VBoAJ04ncOxHno297.m4a"}]}}
    for i in list:
        src=i['src']
        name=i['trackName']
        resource=requests.get(src)
        with open('mp4/%s' % name,'ab') as f:
            f.write(resource.content)
"""
这个是多行注释，真的牛逼！
"""